import time

from Pages.LoginPage import LoginPage
from Pages.LoginAdmin import LoginAdmin


class Login(object):
    #登录
    def LoginOBT(self, Url, userid, password):
        login = LoginPage(Url)
        login.open()
        time.sleep(1)
        #if login.Element_displayed(*login.backToLogin_loc):
        #    login.smart_click(*login.backToLogin_loc)
        login.wait_loadingmask_disappear(1)
        login.input_userid(userid)
        login.input_password(password)
        login.click_checkBox()
        login.click_login()

    def LoginAdmin(self, Url, userid, password):
        login = LoginAdmin(Url)
        login.open()
        time.sleep(1)
        login.wait_loadingmask_disappear(1)

        #已快捷登录成功
        if login.alreadyLogin():
            pass
        elif login.Element_displayed(*login.starFish_loc):
            login.quickLogin()
        else:
            login.refresh_window()
            time.sleep(5)
            if login.alreadyLogin():
                pass
            else:
                login.switchToLoginByPassword()
                time.sleep(1)
                login.input_userid(userid)
                login.input_password(password)
                login.click_weeklyFree()
                login.click_login()
        time.sleep(3)
        login.refresh_window()
        time.sleep(3)

